package com.halflife.framework.generator.template.mapper;

/**
 * Created by zhaoyf on 2018/6/18.
 */
public class InsertAnalysis extends BaseAnalysis {
    public InsertAnalysis(Class clazz) {
        super(clazz);
        this.isTwoAnalysis =true;
    }

    @Override
    protected void setPrefix() {
        this.xmlStr.append("<insert id=\"insert\" keyProperty=\"id\" useGeneratedKeys=\"true\" parameterType=\""+this.clazz.getName()+"\">\n");
        this.xmlStr.append("\t insert into `"+this.tableName+"` (");

    }


    @Override
    protected String getValue1(CustomField customField) {
        if (!customField.isPersist()) {
            return "";
        }
        StringBuilder sb = new StringBuilder();
        sb.append(customField.getRealName());
        sb.append("  ");
        return sb.toString();
    }

    protected void middleAnaysis(){
        xmlStr.append(" )\n");
        xmlStr.append("values (\n");
    }
    protected String getValue2(CustomField customField) {
        if (!customField.isPersist()) {
            return "";
        }
        StringBuilder sb = new StringBuilder();
        sb.append("#{");
        sb.append(customField.getName());
        sb.append(",jdbcType=").append(customField.getTypeName()).append("}");
        sb.append("  ");
        return sb.toString();
    }

    ;

    protected void setSuffix() {

        this.xmlStr.append( " )\n </insert>");
    }

    ;
}
